/*
 *  Copyright 2012 Dirk Vranckaert
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.vranckaert.vvl.utils.view;

import android.util.Log;
import android.widget.LinearLayout;
import eu.vranckaert.vvl.R;
import eu.vranckaert.vvl.activities.DashboardActivity;
import eu.vranckaert.vvl.activities.test.MyActivityTestCase;

/**
 * User: DIRK VRANCKAERT
 * Date: 24/02/12
 * Time: 15:22
 */
public class CustomTextViewTest extends MyActivityTestCase<DashboardActivity> {
    private static final String LOG_TAG = CustomTextViewTest.class.getSimpleName();

    public CustomTextViewTest() {
        super(DashboardActivity.class);
    }

    private CustomTextView createCustomTextView() {
        final LinearLayout container = (LinearLayout) getActivity().findViewById(R.id.home_root);
        final CustomTextView customTextView = new CustomTextView(getActivity());
        
        try {
            runTestOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.i(LOG_TAG, "Removing all views from the activity");
                    container.removeAllViews();
                    Log.i(LOG_TAG, "Adding the multi select spinner to the activity");
                    container.addView(customTextView);
                }
            });
        } catch (Throwable throwable) {}

        return customTextView;
    }
    
    private void testTextViewText(final CustomTextView textView, final String text) {
        try {
            runTestOnUiThread(new Runnable() {
                @Override
                public void run() {
                    textView.setText(text);
                }
            });
        } catch (Throwable throwable) {}
    }

    public void testCustomTextView() {
        CustomTextView textView = createCustomTextView();
        testTextViewText(textView, "test");

        assertEquals("test", textView.getText());
        solo.clickOnView(textView);
        testTextViewText(textView, "TEST_AZERTY");
        assertEquals("TEST_AZERTY", textView.getText());
    }
}
